package cn.com.inossem.adapter;

import java.util.List;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import cn.com.inossem.activity.InputActivity;
import cn.com.inossem.activity.R;
import cn.com.inossem.model.RetrieveInfoModel;

public class InputAdapter extends BaseAdapter {
	private InputActivity mContext;
	private List<RetrieveInfoModel> list;
	private int type = 0;

	public InputAdapter(InputActivity context, List<RetrieveInfoModel> list,
			int type) {
		this.mContext = context;
		this.list = list;
		this.type = type;
	}

	public void setList(List<RetrieveInfoModel> list) {
		this.list = list;
	}

	@Override
	public int getCount() {
		System.out.println("listsize:" + list.size());
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = LayoutInflater.from(mContext);
		convertView = inflater.inflate(R.layout.inputtext, null);
		TextView textview = (TextView) convertView.findViewById(R.id.textview);

		textview.setText(list.get(position).getName());

		convertView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				//intent.putExtra("id", list.get(position).getId());
				intent.putExtra("name", list.get(position).getName());
				//System.out.println("name:"+list.get(position).getName());
				intent.putExtra("nameid", list.get(position).getId()+"");
				//System.out.println("nameid"+list.get(position).getId()+"");
				//intent.putExtra("position", mContext.position);
				mContext.setResult(10010, intent);
				mContext.finish();
			}
		});
		return convertView;
	}
}